<?php
	/**
	* Gestion des Cours 
	*
	*/
	class Cours {
	
		var $libelle;
		var $nature;
		var $code_ECUE;
		var $ECUE;
		var $volume_horaire;
		var $volume_TP;
		var $volume_TD;
		var $coeifficient;
		var $mots_cles;
		var $resume;
		var $diplome;
		var $niveau;  
		var $semestre;  
		var $domaine;  
		var $mention;
		var $nbr_ens;
		var $etat_soumission;
		var $coconcepteur;
		var $code_ue;
		/**
		* Ajout d'un nouveau cours.	
		*
		*
		*/		
		function addCours($tab){
			$db = new Db();
			$db->connect();
			
			// Ajout ds la table des unit�s
			$sql = "INSERT into unite (lib_unite, nature_unite, ECUE, volume_cours, volume_TP, volume_TD, coeifficient, code_diplome, code_niveau, code_domaine, date_soumission, credit, CIN, code_mention, specialite, session,etat_soumission) VALUES ('".$tab["lib_unite"]."','".$tab["nature_unite"]."','".$tab["ECUE"]."','".$tab["volume_cours"]."','".$tab["volume_TP"]."','".$tab["volume_TD"]."','".$tab["coeifficient"]."','".$tab["code_diplome"]."','".$tab["code_niveau"]."','".$tab["code_domaine"]."','".$tab["date_soumission"]."','".$tab["credit"]."','".$tab["CIN"]."','".$tab["code_mention"]."','".$tab["specialite"]."','".session_id()."','".$tab["etat_soumission"]."')";

			$req = $db->query($sql);
			
			$id = $this->getLastID();
			
			// ~ Mise a jours dans la table unite&enseignant ~
			$sql = "UPDATE ens_ue SET code_ue = '$id' WHERE code_ue = '".session_id()."'";
			$req = $db->query($sql);


			return $id; 
			$db->disconnect();
		}


		/**
		* Modifier L'Utilisateur.	
		*
		*
		*/
		function editCours($tab){
			$db = new Db();
			$db->connect();

			$sql = " UPDATE unite    SET 	coconcepteur             = '".$tab["coconcepteur"]."'   
											
							WHERE code_ue	= '".$tab["code_ue"]."'";
			$req = $db->query($sql);

			$db->disconnect();
		}
		/**
		* Suppresion de l'utilisateur .	
		*
		*
		*/
		function delCours($code){
			$db = new Db();
			$db->connect();
			//Suppresion de la table enseignant
			$sql = " DELETE FROM enseignant WHERE code = $code";
			$req = $db->query($sql);
			
			//Suppresion de la table ens_ue.
			$sql_ens_ue = " DELETE FROM ens_ue WHERE code_ens = $code";
			$req_ens_ue = $db->query($sql_ens_ue);
			$db->disconnect();
		}

		/**
		* Retourne un Utilisateur.	
		*
		*
		*/
		function getCours($code){
			$db = new Db();
			$db->connect();
			
				$sqlSelect = " SELECT * FROM enseignant  WHERE code = $code";
				$reqSelect = $db->query($sqlSelect);
				return $db->fetchObject();
				
			    $db->disconnect();
		}
  
  

		function getCoursBySession($idsession){
			$db = new Db();
			$db->connect();
			
				$sqlSelect = "SELECT code_ue as IdUe FROM `unite`  WHERE session = '$idsession'";
				$reqSelect = $db->query($sqlSelect);
				$resSelect = $db->fetchObject();
		        return $resSelect->IdUe;
				
			    $db->disconnect();
		}  
	   
	   /**
		* Recuprer id du dernier enregistrement.
		*
		*/
		function getLastID(){
			$db = new Db();
			$db->connect();

			$sqlSelect = "SELECT `code_ue` as IdUe FROM unite where cin = '".$_SESSION["cin"]."'";
			$reqSelect = $db->query($sqlSelect);
			$resSelect = $db->fetchObject();
			return $resSelect->IdUe;
			
			$db->disconnect();
		}
	function lastid(){
		$db = new Db();
		$db->connect();
		
		$sqlSelect = "SELECT code_ue as IdUe
                       FROM `unite`
                       ORDER BY code_ue DESC
                       LIMIT 1 ";
					   
		$reqSelect = $db->query($sqlSelect);
		$resSelect = $db->fetchObject();
		return $resSelect->IdUe;
			
			$db->disconnect();
		
   	}
	
		/**
		* Indexation.
		*
		*/
	    function coursAssignIndexation($tab)
		{
		 	$db = new Db();
			$db->connect();
			
			// Ajout ds la table des unit�s
			$sql = "INSERT into indexation (code_ue, titre, discipline, mots_cles, date_creation, public_cible, objectif, nature, description) VALUES ('".$tab["code_ue"]."','".$tab["titre"]."','".$tab["discipline"]."','".$tab["mots_cles"]."','".$tab["date_creation"]."','".$tab["public_cible"]."','".$tab["objectif"]."','".$tab["nature"]."','".$tab["description"]."')";
			$req = $db->query($sql);

			$db->disconnect(); 
		
		}
	
	
	}
	

?>